<template>
	<div>
		<smpPanel>
			<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="query.body">
				<el-row>

					<el-col :span="6">
						<el-form-item label="字典编码:" prop="dictCode">
							<el-select v-model="query.body.dictCode" filterable placeholder="" style="width: 100%;">
								<el-option v-for="item in dict('SMP0001')" :key="item.itemCode" :label="item.itemName"
									:value="item.itemCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="状态:" prop="status">
							<el-select v-model="query.body.status" placeholder="" style="width: 100%;">
								<el-option v-for="item in dict('SMP0005')" :key="item.itemCode" :label="item.itemName"
									:value="item.itemCode">
								</el-option>
							</el-select>
						</el-form-item>
					</el-col>

					<el-col :span="6">
						<searchButtonGroup @search="getList" @reset="reset" online />
					</el-col>
				</el-row>
				</el-row>
			</el-form>
		</smpPanel>


		<smpPanel>
			<createButton slot="option" @click="adddataDictionary" />
			<el-table :data="list" size="mini" stripe border style="width: 100%">

				<el-table-column prop="dictCode" label="字典编码">
					<!-- 	<template slot-scope="scope">
							{{scope.row.dictCode|dictName("SMP0001")}}
						</template> -->
				</el-table-column>

				<el-table-column prop="dictName" label="字典编码名称">
					<template slot-scope="scope">
						{{scope.row.dictCode|dictName("SMP0001")}}
					</template>
				</el-table-column>

				<el-table-column prop="itemCode" label="字典项编码" width="300">
				</el-table-column>

				<el-table-column prop="itemName" label="字典项目名称">
				</el-table-column>

				<el-table-column prop="status" label="状态">
					<template slot-scope="scope">
						{{scope.row.status|dictName("SMP0005")}}
					</template>
				</el-table-column>

				<el-table-column label="操作" align="center" width="150">
					<template slot-scope="scope">
						<el-link size="mini" type="primary" :underline="false" style="font-size: 12px;"
							@click="handleEdit(scope.$index, scope.row)">修改</el-link>
						<el-divider direction="vertical"></el-divider>
						<el-link size="mini" type="primary" :underline="false" style="font-size: 12px;"
							@click="delrole(scope.$index, scope.row)">删除</el-link>
					</template>
				</el-table-column>

			</el-table>
			<div class="smp-pagination" v-show="total>0">
				<el-pagination background size="medium" layout="total,sizes,prev, pager, next,jumper"
					:page-size="query.pageSize" :page-sizes="[5,10,15,20]" :total="total" :current-page="query.pageNum"
					@current-change="currentChange" @size-change="sizeChange">
				</el-pagination>
			</div>
		</smpPanel>

		<dataDictionaryEdit ref="dataDictionaryEdit" @fresh="fresh" />
		<dataDictionary ref="dataDictionary" @fresh="fresh" />
		<dataDictionaryDel ref="dataDictionaryDel" @fresh="fresh" />

	</div>
</template>

<script>
	"use strict";
	import {
		selectByPage,
		deletedataDictionary
	} from '@/api/dataDictionary.js';
	import dataDictionary from "./dataDictionary";
	import dataDictionaryEdit from "./dataDictionaryEdit";
	import dataDictionaryDel from "./dataDictionaryDel";
	export default {
		data() {
			return {
				list: [],
				query: {
					body: {
						dictCode: "",
						itemCode: "",
						itemName: "",
						status: ""
					},
					pageNum: 1,
					pageSize: 5
				},
				total: 0
			};
		},
		created() {
			Object.assign(this.query.body, this.$route.query);
			if (this.$route.query.pageNum != undefined) {
				this.query.pageNum = this.$route.query.pageNum;
			}
			if (this.$route.query.pageSize != undefined) {
				this.query.pageSize = parseInt(this.$route.query.pageSize);
			}
			this.getList();
		},
		components: {
			dataDictionary,
			dataDictionaryEdit,
			dataDictionaryDel,
		},
		methods: {

			adddataDictionary() {
				this.$refs["dataDictionary"].ShowDialog();
			},

			/**
			 * @param {Object} index
			 * @param {Object} row
			 */
			handleEdit(index, row) {
				this.$refs.dataDictionaryEdit.ShowDialog(row);
			},

			delrole(index, row) {
				this.$confirm('确认要删除字典项吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					deletedataDictionary(row).then(response => {
						if (response.data.code == "0000") {
							this.$message.success(response.data.message);
							this.getList();
						} else {
							this.$message.error(response.data.message);
						}
					}).catch(error => {
						this.$message.error(error.message);
					});
				}).catch(() => {
					this.$message({
						duration: 5000,
						type: 'info',
						message: '已取消删除'
					});
				});


				/* this.$refs.dataDictionaryDel.ShowDialog(row); */
			},


			getList() {

				selectByPage(this.query).then(response => {
					this.list = response.data.extend.list
					this.total = response.data.extend.total;

					let query = {};
					Object.assign(query, this.query.body);
					query.pageNum = this.query.pageNum;
					query.pageSize = this.query.pageSize;
					this.$router.push({
						query: query
					})
					// alert(this.total);
				}).catch(error => {
					console.info("失败");
					console.info(error.message);
				});
			},

			currentChange(val) {
				this.query.pageNum = val;
				this.getList();
			},
			sizeChange(val) {
				this.query.pageSize = val;
				this.query.pageNum = 1;
				this.getList();
			},
			fresh() {
				this.getList();
			}

		}
	}
</script>

<style>
</style>
